home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / ProcDoggie 1.0a6⁄THINK P / UProcessLDEF.p < prev    next >
Encoding:
Text File  |  1991-02-21  |  7.0 KB  |  213 lines  |  [TEXT/PJMM]

  1. unit UProcessLDEF;
  2.  
  3. {-------------------------------------------------------------------------------}
  4. {#}
  5. {#    Apple Macintosh Developer Technical Support}
  6. {#}
  7. {#    Data structures for process-list LDEF}
  8. {#}
  9. {#    Program:    ProcDoggie}
  10. {#    File:        ProcessLDEF.p - Pascal Implementation}
  11. {#}
  12. {#    by:        Forrest Tanaka}
  13. {#}
  14. {#    Copyright © 1988-1991 Apple Computer, Inc.}
  15. {#    All rights reserved.}
  16. {#}
  17. {--------------------------------------------------------------------------------}
  18. {#}
  19. {#    This LDEF is a simple replacement for the standard LDEF.  The only advantange}
  20. {#    this LDEF has over the standard LDEF is that it contains information specific}
  21. {#    to processes that aren’t displayed.  This is to make identifying processes in}
  22. {#    the Process List window easier.}
  23. {#}
  24. {#    Once the icon utilities are released to the developer community, this LDEF}
  25. {#    will be updated to display the icon of each process in the list.}
  26. {#}
  27. {-------------------------------------------------------------------------------}
  28. {[j=20/57/1$] Pasmat Options}
  29. {$R-}
  30.  
  31. {-------------------------------------------------------------------------------}
  32. {#}
  33. {#     2/21/91 pvh - THINK Pascal conversion.}
  34. {#    Notes:}
  35. {#}
  36. {-------------------------------------------------------------------------------}
  37.  
  38. interface
  39.  
  40.  
  41. (*******************************************************************************}
  42. {* Used Units}
  43. {*******************************************************************************)
  44.  
  45.     uses
  46.         (* Group 1 *)
  47.         Types, QuickDraw, 
  48.  
  49.         (* Group 2 *)
  50.         Events, OSUtils, SegLoad, SysEqu, TextEdit, ToolUtils, 
  51.  
  52.         (* Group 3 *)
  53.         Files, Lists, Processes, Script;
  54.  
  55.  
  56. (*******************************************************************************}
  57. {* Types}
  58. {*******************************************************************************)
  59.  
  60.     type
  61.         ProcessListInfoRec = record
  62.                 processName: Str31;               {Process’s name}
  63.                 serialNumber: ProcessSerialNumber  {Process’s serial number}
  64.             end;
  65.         ProcessListInfoPtr = ^ProcessListInfoRec;
  66.  
  67.  
  68. {$S Main}
  69. (*******************************************************************************}
  70. {* ProcessList - Entry point to the List Definition Procedure}
  71. {*}
  72. {* This is the entry point to the custom list defproc used in ProcDoggie.  It}
  73. {* isn’t really intended to be called directly from any part of this application,}
  74. {* I’m just including it in the INTERFACE portion so that the linker has}
  75. {* something to grab onto.}
  76. {*******************************************************************************)
  77.  
  78.     procedure ProcessList (message: Integer; selectCell: Boolean; cellRect: Rect; theCell: Cell; dataOffset: Integer; dataLength: Integer; theList: ListHandle);
  79.  
  80.  
  81. implementation
  82.  
  83.     const
  84.         kCellMargin = 3; {Margin between list contents and list edge in pixels}
  85.  
  86.  
  87.     procedure DrawCell (cellRect: Rect; theCell: Cell; selected: Boolean; theList: ListHandle; dataOffset: Integer);
  88.     FORWARD;
  89.     procedure HilightCell (cellRect: Rect);
  90.     FORWARD;
  91.  
  92.  
  93. {$S Main}
  94. (*******************************************************************************}
  95. {* Public: ProcessList}
  96. {*}
  97. {* Here’s the entry point to my custom LDEF.  Yup.}
  98. {*******************************************************************************)
  99.  
  100.     procedure ProcessList (message: Integer; selectCell: Boolean; cellRect: Rect; theCell: Cell; dataOffset: Integer; dataLength: Integer; theList: ListHandle);
  101.  
  102.     begin
  103.         if message = lDrawMsg then
  104.             begin
  105.                 if dataLength > 0 then
  106.                     DrawCell(cellRect, theCell, selectCell, theList, dataOffset)
  107.             end
  108.         else if message = lHiliteMsg then
  109.             HilightCell(cellRect)
  110.     end;
  111.  
  112.  
  113. {$S Main}
  114. (*******************************************************************************}
  115. {* Private: DrawCell - Draw the contents of the specified cell}
  116. {*}
  117. {* This routine draws the contents of the cell specified by theCell into it’s}
  118. {* rectangle, which is specified by cellRect.  In case the font is too large for}
  119. {* the cell rectangle, I set the clip region to cellRect before drawing the cell}
  120. {* text, then set it back to what it was afterwards.}
  121. {*}
  122. {* If selected is TRUE, then theCell is selected.  In that case, my HilightCell}
  123. {* routine is called to hilight the cell.}
  124. {*}
  125. {* The list that this all takes place in is specified by theList.}
  126. {*******************************************************************************)
  127.  
  128.     procedure DrawCell (cellRect: Rect; theCell: Cell; selected: Boolean; theList: ListHandle; dataOffset: Integer);
  129.  
  130.         var
  131.             cellInfo: ProcessListInfoRec; {Information for cell to be drawn}
  132.             currClip: RgnHandle;          {Handle to the current clip region}
  133.             currPen: PenState;           {Current pen characteristics}
  134.             currFont: FontInfo;           {Current font characteristics}
  135.             dataLen: Integer;            {Length of cell data in bytes}
  136.             marginRect: Rect;               {Rect that process name is drawn into}
  137.             alignment: Integer;            {Alignment of process name text}
  138.             spareSpace: Integer;            {marginRect width - text width}
  139.  
  140.     begin
  141.         (* Save the current pen state and set the default pen characteristics *)
  142.         GetPenState(currPen);(*<*)
  143.         PenNormal;
  144.  
  145.         (* Save the current clip region and set it to cellRect *)
  146.         currClip := NewRgn;
  147.         GetClip(currClip);(*<*)
  148.         ClipRect(cellRect);
  149.  
  150.         (* Will draw text into the cell rect with a margin on left and right *)
  151.         marginRect := cellRect;
  152.         InsetRect(marginRect, kCellMargin, 0);(*◊*)
  153.  
  154.         (* Get the information for the specified cell *)
  155.         dataLen := SIZEOF(ProcessListInfoRec);
  156.         LGetCell(Ptr(@cellInfo), dataLen, theCell, theList);(*<*)
  157.  (*◊*)
  158.  
  159.         (* To find where to draw the cell’s text, get current font information *)
  160.         GetFontInfo(currFont);(*<*)
  161.  
  162.         (* Position the pen for drawing the text *)
  163.         MoveTo(marginRect.left, marginRect.top + currFont.ascent);
  164.  
  165.         (* Determine whether system script is left-to-right or right-to-left *)
  166.         if GetSysJust = 0 then
  167.             alignment := teFlushLeft
  168.         else
  169.             alignment := teFlushRight;
  170.  
  171.         (* Adjust the pen for right-aligned text if script is right-to-left *)
  172.         if alignment = teFlushRight then
  173.             begin
  174.                 spareSpace := marginRect.right - marginRect.left - StringWidth(cellInfo.processName);
  175.                 Move(spareSpace, 0);
  176.             end;
  177.  
  178.         (* Draw the cell’s contents *)
  179.         EraseRect(cellRect);
  180.         DrawString(cellInfo.processName);
  181.  
  182.         (* If the cell is selected, hilight it *)
  183.         if selected then
  184.             HilightCell(cellRect);
  185.  
  186.         (* Restore the current clip region and pen *)
  187.         SetClip(currClip);
  188.         DisposeRgn(currClip);
  189.         SetPenState(currPen);
  190.     end;
  191.  
  192.  
  193. {$S Main}
  194. (*******************************************************************************}
  195. {* Private: HilightCell - Hilight the specified cell}
  196. {*}
  197. {* This routine hilights the cell whose rectangle is cellRect.  I also clear the}
  198. {* hilight bit of the HiliteMode low-memory global.  If this is running on a}
  199. {* Color QuickDraw machine, then background hilighting is done instead of}
  200. {* the usual inversion.}
  201. {*******************************************************************************)
  202.  
  203.     procedure HilightCell (cellRect: Rect);
  204.  
  205.     begin
  206.         (* Do the fancy, new kind of hilighting on a Color QuickDraw Mac *)
  207.         BitClr(Ptr(HiliteMode), pHiliteBit);
  208.  
  209.         (* Now, hilight the cell *)
  210.         InvertRect(cellRect)
  211.     end;
  212.  
  213. end.